package com.changgou.system.config;

import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.io.Serializable;

/**
 * @author BAO
 * @version V1.0
 * @Package com.changgou.system.config
 * @date 2020/12/8 15:06
 * @description:
 */
@Configuration
public class BaseConfig implements Serializable {

    @Bean
    public KeyResolver ipKeyResolver(){
       return new KeyResolver(){
            @Override
            public Mono<String> resolve(ServerWebExchange exchange) {
                Mono<String> hostname = Mono.just(exchange.getRequest().getRemoteAddress().getHostName());
                return hostname;
            }
       };
    }
}
